package com.ycrlkj.android.modulescore.main.viewmodel;

import android.annotation.SuppressLint;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import com.ycrlkj.android.modulescore.main.entity.FreightOrder;
import com.ycrlkj.android.modulescore.main.entity.XxAppointment;
import com.ycrlkj.android.modulescore.main.entity.XxStation;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class XxAppointmentViewModel extends ViewModel {

    public MutableLiveData<XxAppointment> xxAppointment;
    public MutableLiveData<XxAppointment> getXxAppointment(){
        if(xxAppointment == null){
            xxAppointment = new MutableLiveData<>();
            xxAppointment.setValue(new XxAppointment());
        }
        return xxAppointment;
    }

    public MutableLiveData<FreightOrder> freightOrder;
    public MutableLiveData<FreightOrder> getFreightOrder(){
        if(freightOrder == null){
            freightOrder = new MutableLiveData<>();
            freightOrder.setValue(new FreightOrder());
        }
        return freightOrder;
    }

    public MutableLiveData<XxStation> xxStation;
    public MutableLiveData<XxStation> getXxStation(){
        if(xxStation == null){
            xxStation = new MutableLiveData<>();
            xxStation.setValue(new XxStation());
        }
        return xxStation;
    }


    /* #region ========================= 预约时间 开始 ====================== */
    public MutableLiveData<String[]> appointmentTimeArr;
    public MutableLiveData<String> appointmentTime;
    public MutableLiveData<Integer> appointmentTimePosition;

    public MutableLiveData<String[]> getAppointmentTimeArr() {
        if (appointmentTimeArr == null) {
            appointmentTimeArr = new MutableLiveData<>();

            String[] dates = new String[3];

            @SuppressLint("SimpleDateFormat")
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

            Date todayDate = new Date();
            String today = sdf.format(todayDate);

            Calendar calendar = new GregorianCalendar();
            calendar.setTime(todayDate);

            calendar.add(Calendar.DATE, 1);
            String tomorrow = sdf.format(calendar.getTime());

            calendar.add(Calendar.DATE, 1);
            String thirdDate = sdf.format(calendar.getTime());

            dates[0] = today;
            dates[1] = tomorrow;
            dates[2] = thirdDate;

            appointmentTimeArr.setValue(dates);
        }
        return appointmentTimeArr;
    }

    public MutableLiveData<String> getAppointmentTime() {
        if (appointmentTime == null) {
            appointmentTime = new MutableLiveData<>();
            appointmentTime.setValue("");
        }
        return appointmentTime;
    }

    public MutableLiveData<Integer> getAppointmentTimePosition() {
        if (appointmentTimePosition == null) {
            appointmentTimePosition = new MutableLiveData<>();
            appointmentTimePosition.setValue(0);
        }
        return appointmentTimePosition;
    }
    /* #endregion ====================== 预约时间 结束 ====================== */

}
